package com.hs.controller;

import com.github.pagehelper.PageInfo;
import com.hs.entity.RestBean;
import com.hs.entity.dto.TeamType;
import com.hs.service.TeamTypeService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/api/teamType")
public class TeamTypeController {
    @Resource
    private TeamTypeService teamTypeService;

    @GetMapping("/getTeamTypeList/{currentNum}")
    public RestBean<PageInfo<TeamType>> getTeamTypeList(
            @PathVariable("currentNum") Integer currentNum,
            @RequestParam(required = false) String keywords) {
        PageInfo<TeamType> teamTypeList = teamTypeService.selectTeamTypeList(currentNum,keywords);
        return RestBean.success(teamTypeList);
    }

    @GetMapping("/getAllTeamTypeList")
    public RestBean<List<TeamType>> getAllTeamTypeList() {
        List<TeamType> teamAllTypeList = teamTypeService.getAllTeamTypeList();

        return RestBean.success(teamAllTypeList);
    }

    @PostMapping("/updateTeamType")
    public RestBean<TeamType> updateTeamType( @RequestBody TeamType teamType) {
        System.out.println(teamType);
        teamTypeService.updateById(teamType);
        return RestBean.success(null);
    }

    @PostMapping("/addTeamType")
    public RestBean<TeamType> addTeamType( @RequestBody TeamType teamType) {
        teamType.setCreate_time(LocalDateTime.now());
        teamTypeService.save(teamType);
        return RestBean.success(null);
    }

    @PostMapping("/deleteTeamType/{id}")
    public RestBean<TeamType> deleteTeamType(@PathVariable  Integer id) {
        teamTypeService.removeById(id);
        return RestBean.success(null);
    }

}
